//
//  AlertManager.m
//  TESTAlert
//
//  Created by mymac on 2017/2/9.
//  Copyright © 2017年 谢增文 All rights reserved.
//

#import "AlertManager.h"

@implementation AlertManager


+(instancetype)sharedManager {
    
    static AlertManager *mager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
       mager = [[AlertManager alloc]init];

    });
    
    return mager;
    
    
}

-(void)alert:(AlertStyle)style withPrepare:(nonnull UIViewController *)zw_self title:(NSString  *__nullable)title content:(nonnull NSString *)content theFirstButton:(void(^__nullable)())confirm theSecondButton:(void(^__nullable)())cancel {
    
    static UIAlertController *alert;
    static UIAlertAction *actionOne;
    static UIAlertAction *actionTwo;
    
    if (!_oneButtonTitle) {
        _oneButtonTitle = @"确定";
    }
    if (!_twoButtonTitle) {
        
        _twoButtonTitle = @"取消";
    }
    if (style == TitleOnlyOneButtonAlertStyle) {
        alert = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
        
        actionOne = [UIAlertAction actionWithTitle:_oneButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            if (confirm) {
                confirm();
            }
       
        }];
        
        [alert addAction:actionOne];

    } else {
        alert = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
        
        actionOne = [UIAlertAction actionWithTitle:_oneButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (confirm) {
                confirm();
            }
        }];
        
        actionTwo = [UIAlertAction actionWithTitle:_twoButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (cancel) {
                cancel();
            }
        }];
        
        [alert addAction:actionOne];
        
        [alert addAction:actionTwo];

    }


    [zw_self presentViewController:alert animated:YES completion:nil];
   
    
    
    
    
}





@end
